# import json
#
# with open(r'E:\xiangmu\en\a.json', 'r', encoding='utf-8') as f:
#     data = f.read()
#
# res = json.loads(data)[:2]
#
# print("".join(res))


import os
import json
import csv

csv_data = []

folder_path = r'E:\xiangmu\en\en\spiders\data'
file_name_lst = os.listdir(folder_path)
for item in file_name_lst:
    full_path = os.path.join(folder_path, item)
    with open(full_path, 'r', encoding='utf-8') as f:
        data = json.loads(f.read())
    for item in data['Data']['Table2']:
        title = item['MovieName']
        pf = int(item['BoxOffice']/10000)
        cc = item['ShowCount']
        sr = int(item['AvgShowBox'])
        csv_data.append([title, pf, cc, sr])

with open('a.csv', 'w', encoding='utf_8_sig', newline='') as f:
    f_csv = csv.writer(f)
    f_csv.writerow(['电影名', '票房', '场次', '收入'])
    f_csv.writerows(csv_data)